<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机获取一条笑话</title>
</head>

<body>
    <div id="joke">
        <input type="button" value="获取一条笑话" @click="getjoke">
        <p v-text="joke"></p>
    </div>

    <script src="./lib/axios.js"></script>
    <script src="./lib/vue.js"></script>
    <script>
        var joke = new Vue({
            el: "#joke",
            data: {
                joke: "笑话"
            },
            methods: {
                async getjoke() {
                    // 由于axios内的this会发送改变 所以我们先存一份，然后再axios中
                    // var that = this;
                    const res = await axios({
                        method: "GET",
                        url: "https://autumnfish.cn/api/joke",
                    });
                    this.joke = res.data

                }
            }
        })
    </script>

</body>

</html>